package zhaoyong.wang.request;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhaoyong.wang.pojo.User;

import javax.xml.transform.sax.SAXResult;
import java.time.LocalDateTime;

//原始方式
/*@RestController
public class Requestcontroller {
    @RequestMapping("/simpleParam")
    public String simpleParam(HttpServletRequest request){
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        int i = Integer.parseInt(age);
        System.out.println(name + ":" + age );
        return "OK";
    }
}*/
//SpringBoot方式
@RestController
public class Requestcontroller {
    @RequestMapping("/simpleParam")
    public String simpleParam(String name, Integer age){
        System.out.println(name + ":" + age );
        return "OK";
    }
    @RequestMapping("simplePojo")
    public String simplePojo(User user){
        System.out.println(user);
        return "OK";
    }
    @RequestMapping("complexPojo")
    public String complexPojo(User user){
        System.out.println(user);
        return "OK";
    }
    @RequestMapping("/dataParm")
    public String dataParm(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime updataTime){
        System.out.println(updataTime);
        return "ok";
    }
    @RequestMapping("/jsonParm")
    public String jsonParm(@RequestBody User user){
        System.out.println(user);
        return "ok";
    }
}

